 package org.dzms.dao;

import java.util.List;

import org.dzms.commons.DataHandler;
import org.dzms.commons.IPage;
import org.dzms.commons.PageHandler;
import org.dzms.commons.sqlHandler;
import org.dzms.entity.Group;
import org.dzms.entity.HomePage;

public class groupDAO implements IPage{
	/**
	 * ========================================================
	 * 												团购详情查询
	 * ========================================================
	 */
	//查询所有团购详情信息
	public List<Group> findAllGp() {
		String sql = "select *from groups";
		return DataHandler.query(sql, null, Group.class);
	}
	//保存团购详情信息
	public void saveGp(Group gp) {
		String sql = "insert into groups(gppic, gpshaname, gpshdet, gpshprice, "
													  + "gpshrelprice, gpsellnum, gplv, gpbulkevanum) values(?,?,?,?,?,?,?,?)";
		DataHandler.update(sql, new Object[]{gp.getGppic(), gp.getGpshname(), gp.getGpshdet(), 
																		 gp.getGpshprice(), gp.getGpshrelprice(), gp.getGpsellnum(), 
																		 gp.getGplv(), gp.getGpbulkevanum()});
	}
	//删除团购详情信息
	public void deleteGp(int gpid) {
		String sql = "delete from groups where gpid=?";
		DataHandler.update(sql, new Object[]{gpid});
	}
	//新增团购详情信息
	public void updateGp(Group gp) {
		String sql = "update groups set gppic=?, gpshaname=?, gpshdet=?, "
													   + "gpshprice=?, gpshrelprice=?, gpsellnum=?, "
													   + "gplv=?, gpbulkevanum=? where gpid=?";
		DataHandler.update(sql, new Object[]{gp.getGppic(), gp.getGpshname(), gp.getGpshdet(), 
																		 gp.getGpshprice(), gp.getGpshrelprice(), gp.getGpsellnum(), 
																		 gp.getGplv(), gp.getGpbulkevanum(), gp.getGpid()});
	}
	
	public <E> List<E> findCurrentPageData(PageHandler handler) {
		String sql = "select * from groups limit ?,?";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return DataHandler.query(sql, new Object[]{(handler.getCurrentPage()-1)*handler.getPageSize(),handler.getPageSize()},Group.class);
	}

	public int findCountPage(PageHandler handler) {
		String sql = "select ceil(count(*)/?) from groups";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return Integer.parseInt(DataHandler.uniqueQuery(sql, new Object[]{handler.getPageSize()}).toString());
	}

	public List<Group> findGpById(int gpid) {
		String sql = "select * from groups where gpid="+gpid;
		return DataHandler.query(sql, null, Group.class);
	}
	public <E> List<E> findCurrentPageDatadesc(PageHandler handler) {
		// TODO Auto-generated method stub
		return null;
	}
	public <E> List<E> foods(String a, PageHandler handler) {
		// TODO Auto-generated method stub
		return null;
	}
}
